package com.kordar.admin.modular.sys.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kordar.admin.kernel.wrapper.QueryWrapperEntity;
import com.kordar.admin.modular.sys.entity.AdminEntity;
import com.kordar.admin.modular.sys.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("#kordardb")
public class AdminServiceImpl extends ServiceImpl<AdminMapper, AdminEntity> implements AdminService {

    AdminMapper adminMapper;

    @Autowired
    public void setMenuMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }


    @Override
    public AdminEntity findOne(Long id) {
        return getById(id);
    }

    @Override
    public IPage<AdminEntity> iPage(QueryWrapperEntity<AdminEntity> entity) {
        Page<AdminEntity> page = entity.where(AdminEntity.class).orderBy().queryPage();
        QueryWrapper<AdminEntity> query = entity.getQuery();
        return adminMapper.selectPage(page, query);
    }

    @Override
    public IPage<AdminEntity> excelData(QueryWrapperEntity<AdminEntity> entity, Integer maxPagesize) {
        Page<AdminEntity> page = entity.where(AdminEntity.class).orderBy().queryPage(maxPagesize);
        QueryWrapper<AdminEntity> query = entity.getQuery();
        return adminMapper.selectPage(page, query);
    }

    @Override
    public boolean hasExists(String field, Object object) {
        QueryWrapper<AdminEntity> query = new QueryWrapper<>();
        query.eq(field, object);
        return getOne(query, false) != null;
    }
}
